package com.crawler.selector;

import com.crawler.model.CrawlerRequestInfo;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Service
@Slf4j
public class CssUrlSeletor {


    public Collection<String> addUrls(Document html) {
        Elements hrefElements = html.select("a[href]");
        List<String> urlList=new ArrayList<>();
        if (hrefElements != null && hrefElements.size() > 0) {
            for (Element item : hrefElements) {
                String href = item.attr("abs:href");
                urlList.add(href);
            }
        }
        return urlList;
    }

}
